Introduction to Computation and Programming Using Python by John V. Guttag
Author:John V. Guttag
Language: eng
Format: epub, pdf
Publisher: The MIT Press
Notice that we are computing the same values over and over again. For example, fib gets called with 3 three times, and each of these calls provokes four additional calls of fib. It doesn’t require a genius to think that it might be a good idea to record the value returned by the first call, and then look it up rather than compute it each time it is needed. This is called memoization, and is the key idea behind dynamic programming.
Figure 13.2 contains an implementation of Fibonacci based on this idea. The function fastFib has a parameter, memo, that it uses to keep track of the numbers it has already evaluated. The parameter has a default value, the empty dictionary, so that clients of fastFib don’t have to worry about supplying an initial value for memo. When fastFib is called with an n > 1, it attempts to look up n in memo. If it is not there (because this is the first time fastFib has been called with that value), an exception is raised. When this happens, fastFib uses the normal Fibonacci recurrence, and then stores the result in memo.
Figure 13.2 Implementing Fibonacci using a memo
Download
Introduction to Computation and Programming Using Python by John V. Guttag.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
What's Done in Darkness by Kayla Perrin(26532)
Shot Through the Heart: DI Grace Fisher 2 by Isabelle Grey(19015)
The Fifty Shades Trilogy & Grey by E L James(18969)
Shot Through the Heart by Mercy Celeste(18886)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 10 by Isuna Hasekura and Jyuu Ayakura(16993)
Python GUI Applications using PyQt5 : The hands-on guide to build apps with Python by Verdugo Leire(16886)
Peren F. Statistics for Business and Economics...Essential Formulas 3ed 2025 by Unknown(16810)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 03 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16710)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 01 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16337)
The Subtle Art of Not Giving a F*ck by Mark Manson(14274)
The 3rd Cycle of the Betrayed Series Collection: Extremely Controversial Historical Thrillers (Betrayed Series Boxed set) by McCray Carolyn(14079)
Stepbrother Stories 2 - 21 Taboo Story Collection (Brother Sister Stepbrother Stepsister Taboo Pseudo Incest Family Virgin Creampie Pregnant Forced Pregnancy Breeding) by Roxi Harding(13442)
Scorched Earth by Nick Kyme(12719)
Drei Generationen auf dem Jakobsweg by Stein Pia(10927)
Suna by Ziefle Pia(10851)
Scythe by Neal Shusterman(10280)
International Relations from the Global South; Worlds of Difference; First Edition by Arlene B. Tickner & Karen Smith(9483)
Successful Proposal Strategies for Small Businesses: Using Knowledge Management ot Win Govenment, Private Sector, and International Contracts 3rd Edition by Robert Frey(9320)
This is Going to Hurt by Adam Kay(9110)
